package com.zf.bm.common.core.sys.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zf.bm.common.core.sys.service.ISignInterface;
import com.zf.bm.common.utils.JsonUtils;
import com.zf.bm.modules.system.entity.MonitorAuditLog;
import com.zf.bm.modules.system.service.MonitorAuditLogService;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 事件审计日志签名实现类
 * </p>
 *
 * @author guojing
 * @since 2023-07-06
 */
@Component("log")
public class LogSignServiceImpl implements ISignInterface {
    @Resource
    private MonitorAuditLogService monitorAuditLogService;

    @Override
    public ImmutablePair<String, String> getSignData(Integer id) {
        MonitorAuditLog log = monitorAuditLogService.getById(id);
        if (ObjectUtils.isEmpty(log)) {
            return null;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("user", log.getUser());
        jsonObject.put("operateCommand", log.getOperateCommand());
        jsonObject.put("operateDescr", log.getOperateDescr());
        jsonObject.put("ip", log.getIp());
        jsonObject.put("mac", log.getMac());
        jsonObject.put("eventType", log.getEventType());
        return ImmutablePair.of(JsonUtils.objectToString(jsonObject), log.getSm3());
    }
}
